"""
URL configuration for backed project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.views.generic import RedirectView
from django.conf import settings
from django.conf.urls.static import static
from .auth_views import register_view, login_view, logout_view, current_user_view
from .swagger_views import swagger_ui_view, swagger_docs_view
from .cos_views import upload_avatar, delete_avatar, upload_image
from .admin_views import admin_avatar_management, avatar_preview
from .admin_views import admin_carbon_factors, admin_delete_carbon_factor, admin_seed_carbon_factors, admin_seed_eco_news
from .admin_views import admin_tasks_management, admin_publish_daily_tasks
from .location_views import self_location_view, reverse_geocode_view, distance_view

urlpatterns = [
    path('', RedirectView.as_view(url='/api/docs/', permanent=False)),
   
    path('admin/', admin.site.urls),
    # API文档接口
    path('api/docs/', swagger_ui_view, name='swagger_ui'),  # Swagger UI界面
    path('api/docs/swagger.yaml', swagger_docs_view, name='swagger_docs'),  # Swagger文档文件
    # 认证接口 - xiangsu/ 前缀（用户扩展与认证系统完全合并）
    path('xiangsu/register/', register_view, name='xiangsu_register'),  # 注册
    path('xiangsu/login/', login_view, name='xiangsu_login'),  # 登录
    path('xiangsu/logout/', logout_view, name='xiangsu_logout'),  # 登出
    path('xiangsu/current-user/', current_user_view, name='xiangsu_current_user'),  # 获取当前用户完整信息
    # 腾讯云COS接口
    path('xiangsu/upload/avatar/', upload_avatar, name='xiangsu_upload_avatar'),  # 头像上传
    path('xiangsu/delete/avatar/', delete_avatar, name='xiangsu_delete_avatar'),  # 头像删除
    path('xiangsu/upload/image/', upload_image, name='xiangsu_upload_image'),  # 通用图片上传
    # 头像管理界面
    path('xiangsu/admin/avatars/', admin_avatar_management, name='admin_avatar_management'),  # 头像管理界面
    path('xiangsu/avatar/preview/<int:user_id>/', avatar_preview, name='avatar_preview'),  # 头像预览页面
    # 碳排因子管理界面
    path('xiangsu/admin/carbon/factors/', admin_carbon_factors, name='admin_carbon_factors'),
    path('xiangsu/admin/carbon/factor/delete/', admin_delete_carbon_factor, name='admin_delete_carbon_factor'),
    path('xiangsu/admin/carbon/factors/seed/', admin_seed_carbon_factors, name='admin_seed_carbon_factors'),
    # 环保动态默认数据导入
    path('xiangsu/admin/eco/news/seed/', admin_seed_eco_news, name='admin_seed_eco_news'),
    # 每日任务管理页面与发布接口
    path('xiangsu/admin/tasks/', admin_tasks_management, name='admin_tasks_management'),
    path('xiangsu/admin/tasks/publish/', admin_publish_daily_tasks, name='admin_publish_daily_tasks'),
    # 腾讯地图位置服务接口
    path('xiangsu/self-location/', self_location_view, name='self_location'),  # IP定位
    path('xiangsu/reverse-geocode/', reverse_geocode_view, name='reverse_geocode'),  # 逆地址解析
    path('xiangsu/distance/', distance_view, name='distance'),  # 距离计算
    # 用户管理接口
    path('xiangsu/user/', include('users.urls')),
    # 动态管理接口
    path('xiangsu/', include('community.urls')),
    # 挑战系统接口
    path('xiangsu/challenge/', include('challenge.urls')),
    # 碳足迹接口
    path('xiangsu/carbon/', include('carbon.urls')),
    # 交换物品接口
    path('xiangsu/exchange/', include('exchange.urls')),
    # 城市指南接口
    path('xiangsu/guide/', include('guide.urls')),
    path('xiangsu/rewards/', include('rewards.urls')),
    # 每日任务接口
    path('xiangsu/tasks/', include('tasks.urls')),
    # 位置与距离服务
    path('xiangsu/location/self/', self_location_view, name='location_self'),
    path('xiangsu/location/reverse/', reverse_geocode_view, name='location_reverse'),
    path('xiangsu/location/distance/', distance_view, name='location_distance'),
]

# 开发环境下提供媒体文件服务
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
